﻿#region Copyright (c) 2008 plexBB Team

/*  Copyright (c) 2008 plexBB Team
 *  
 *  This file is free software: you may copy, redistribute and/or modify it  
 *  under the terms of the GNU General Public License as published by the  
 *  Free Software Foundation, either version 2 of the License, or (at your  
 *  option) any later version.  
 *  
 *  This file is distributed in the hope that it will be useful, but  
 *  WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  
 *  General Public License for more details.  
 *  
 *  You should have received a copy of the GNU General Public License  
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

#endregion

using System;
using System.Web.UI;

namespace PlexBB.Controls.Admin
{
    /// <summary>
    /// Base class for all PlexBB.Controls.Admin.AcpXxx classes
    /// </summary>
    public abstract class AcpControlBase : ForumControl
    {
        private Acp _acp;

        protected override void OnLoad(EventArgs e)
        {
            Control parent = NamingContainer;
            while (!(parent is Acp))
            {
                parent = parent.NamingContainer;
            }
            _acp = (Acp)parent;
            _acp.Confirm.YesClick += OnConfirmYesClick;
            _acp.Confirm.NoClick += OnConfirmNoClick;
            _acp.Message.BackToPrevClick += OnMessageBackToPrevClick;
            base.OnLoad(e);
        }

        #region Confirm

        protected void ShowConfirm(string messageTitle, string messageText, string confirmCommand, object confirmArgument)
        {
            Visible = false;
            _acp.Confirm.Visible = true;
            _acp.Confirm.MessageTitle = messageTitle;
            _acp.Confirm.MessageText = messageText;
            _acp.Confirm.ConfirmCommand = confirmCommand;
            _acp.Confirm.ConfirmArgument = confirmArgument;
        }

        protected virtual void OnConfirmYesClick(object sender, ConfirmEventArgs e)
        {
            HideConfirm();
        }

        protected virtual void OnConfirmNoClick(object sender, ConfirmEventArgs e)
        {
            HideConfirm();
        }

        private void HideConfirm()
        {
            Visible = true;
            _acp.Confirm.Visible = false;
        }

        #endregion

        #region Message

        protected void ShowMessage(string messageTitle, string messageText, string backToPrevUrl, bool success, bool showBackToPrev)
        {
            _acp.ModuleControl.Visible = false;
            Message message = _acp.Message;
            message.Visible = true;
            message.MessageTitle = messageTitle;
            message.MessageText = messageText;
            message.BackToPrevUrl = backToPrevUrl;
            message.Success = success;
            message.ShowBackToPrev = showBackToPrev;
        }

        protected virtual void OnMessageBackToPrevClick(object sender, EventArgs e)
        {
            _acp.ModuleControl.Visible = true;
            _acp.Message.Visible = false;
        }

        #endregion
    }
}